{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/4sum/\n",
    "\n",
    "\n",
    "Time Limit Exceeded\n",
    "\n",
    "\n",
    "```python\n",
    "from itertools import combinations\n",
    "\n",
    "class Solution:\n",
    "    def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n",
    "        r = []\n",
    "        for l in combinations(nums, 4):\n",
    "            l = list(l)\n",
    "            l.sort()\n",
    "            if sum(l) == target:\n",
    "                if l not in r:\n",
    "                    r.append(l)\n",
    "        return r\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "```python\n",
    "from itertools import combinations\n",
    "\n",
    "class Solution:\n",
    "    def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n",
    "        # 2022/11/29 06:29\n",
    "        answers = []\n",
    "        for combination in combinations(nums, 3):\n",
    "            number_needed = target - sum(combination)\n",
    "            if number_needed in nums:\n",
    "                nums.remove(number_needed)\n",
    "                possibility = list(combination) + [number_needed]\n",
    "                possibility.sort()\n",
    "                if possibility not in answers:\n",
    "                    answers.append(possibility)\n",
    "        return answers\n",
    "        # 06:35, time out\n",
    "        # 06:55, 'wrong answer', but I think it is right\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
